<template>
	<view style="background-color: #f0f0f0;">
		<view v-if="!loginFlag" class="flex align-center justify-center" style="background-color: white;">
			<text style="font-size: 30rpx; color: gray;">登录后才可以查看哦～</text>
		</view>
		<view v-if="!hasPets" class="flex align-center justify-center" style="background-color: white;">
			<text style="font-size: 30rpx; color: gray;">您还没有领养宠物哦～</text>
		</view>
		<view class="flex align-center justify-center" style="width:750rpx">
			<view class="flex flex-column" style="width: 710rpx; border-radius: 20rpx; background-color: #f0f0f0;">
				<view v-for="(item, index) in mypetsList" :key="index" @click="openPet(item.id)">
					<view class="flex" style="background-color: white; border-radius: 20rpx;">
						<image src="https://www.dogeman.studio/public/uploads/static/centers/center-demo.jpg" style="height: 250rpx; width: 250rpx; border-radius: 20rpx; margin-left: 15rpx; margin-top: 15rpx; margin-bottom: 15rpx;"></image>
						
						<view class="flex flex-column">
							<text style="font-weight: bold; font-size: 45rpx; margin-left: 30rpx; margin-top: 15rpx;">{{item.animalName}}</text>
							<text style="margin-left: 30rpx; font-size: 30rpx;">编号: {{item.id}}</text>
							<view class="flex" style="margin-left: 30rpx; margin-top: 35rpx;">
								<view v-if="item.sterilized === 1" class="flex align-center justify-center pl-1 pr-1 my-2" style="border-radius: 15rpx; background-color: chocolate; margin-left: 5rpx; margin-right: 5rpx;">
									<text style="font-size: 27rpx; color: white; font-weight: bold;">已绝育</text>
								</view>
								
								<view v-if="item.immune === 1" class="flex align-center justify-center pl-1 pr-1 my-2" style="border-radius: 15rpx; background-color: chocolate; margin-left: 5rpx; margin-right: 5rpx;">
									<text style="font-size: 27rpx; color: white; font-weight: bold;">已免疫</text>
								</view>
								
								<view v-if="item.parasite === 1" class="flex align-center justify-center pl-1 pr-1 my-2" style="border-radius: 15rpx; background-color: chocolate; margin-left: 5rpx; margin-right: 5rpx;">
									<text style="font-size: 27rpx; color: white; font-weight: bold;">已驱虫</text>
								</view>
								
							</view>
						</view>
						
					</view>
					<view style="height: 20rpx; background-color: #f0f0f0; width: 750rpx;"></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	// const demo2 = [{
	// 				petid: 'adhsbxbciuhs',
	// 				petname: '小花',
	// 			},{
	// 				petid: 'adhsbxbcxuhs',
	// 				petname: '绿色',
	// 			},{
	// 				petid: 'adhsbxbexuhs',
	// 				petname: '叶子',
	// 			}];
	export default {
		data() {
			return {
				mypetsList: [],
				loginFlag: 0,
				hasPets: 1
			}
		},
		onShow() {
			if(this.$store.state.user){
				this.loginFlag = 1
				this.getmypetsData();
			}
			else{
				this.mypetsList = [];
				this.loginFlag = 0;
			}
			
		},
		methods: {
			openPet(id){
				uni.navigateTo({
					url: '../pets/pets?id='+id
				})
			},
			getmypetsData(){
				return this.$H.get('/rescue_station/byUserIdAni/'+this.$store.state.user.id).then(res=>{
					this.mypetsList = res
					console.log(this.mypetsList)
					if(this.mypetsList.length === 0){
						this.hasPets = 0
					}else{
						this.hasPets = 1
					}
					// console.log(this.centerInfo)
				}).catch(err=>{
				})
				
				
				// this.mypetsList = demo2;
			}
		}
	}
</script>

<style>

</style>
